package com.koocloud.electroplatemanage.controller;

import com.koocloud.electroplatemanage.common.pojo.ResponseTemplate;
import com.koocloud.electroplatemanage.pojo.StorageVo;
import com.koocloud.electroplatemanage.service.StorageService;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: electroplatemanage
 * @description: 仓库控制层
 * @author: zww
 * @create: 2020-11-23 10:30
 */
@RestController
@RequestMapping("/storage")
public class StorageController {
    static Logger log = Logger.getLogger("storage");

    @Autowired
    StorageService storageService;

    /**
     *@Description:全表查询
     *@Param: [page, limit, beginTime, endTime, storageVo]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: zww
     *@date: 2020/11/23
     */
    @RequestMapping(value = "/selectAllData", method = RequestMethod.POST, name = "全表查询")
    public ResponseTemplate selectAllData(String page, String limit,String beginTime,String endTime, StorageVo storageVo) {
        //分页参数为空则赋值0
        if (!StringUtils.isNotEmpty(page)) {
            page = "0";
        }
        if (!StringUtils.isNotEmpty(limit)) {
            limit = "0";
        }
        //查询所有记录 分页
        return storageService.selectAllData(page,limit,beginTime,endTime,storageVo);

    }

    /**
     *@Description:新增一条数据
     *@Param: [request, storageVo]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: zww
     *@date: 2020/11/23
     */
    @RequestMapping(value = "/insert", method = RequestMethod.POST, name = "新增一条数据")
    public ResponseTemplate insert(HttpServletRequest request, @RequestBody  StorageVo storageVo) {
        String userId = request.getHeader("userId");
        //插入一条记录
        return storageService.insert(storageVo,userId);
    }

    /**
     *@Description:逻辑删除一条记录
     *@Param: [workOrderNumber, deleteFlag]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: zww
     *@date: 2020/11/23
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST, name = "逻辑删除一条记录")
    public ResponseTemplate delete(@RequestParam(name="workOrderNumber") String workOrderNumber,@RequestParam(name="deleteFlag") String deleteFlag) {
        //逻辑删除一条记录
        return storageService.delete(workOrderNumber,deleteFlag);
    }

    /**
     *@Description:修改一条记录
     *@Param: [request, storageVo]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: zww
     *@date: 2020/11/23
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST, name = "修改一条记录")
    public ResponseTemplate update(HttpServletRequest request,@RequestBody StorageVo storageVo) {
        String userId = request.getHeader("userId");
        //修改一条记录
        return storageService.update(storageVo,userId);
    }
    /**
     *@Description: 入库确认按钮
     *@Param: [workOrderNumber]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: zww
     *@date: 2020/11/23
     */
    @RequestMapping(value = "/confirmEntryInfo", method = RequestMethod.POST, name = "入库确认")
    public ResponseTemplate confirmEntryInfo(HttpServletRequest request,String workOrderNumber){
        String userId = request.getHeader("userId");
        return storageService.confirmEntryInfo(workOrderNumber,userId);

    }

    /**
     *@Description: 申请发货按钮
     *@Param: [workOrderNumber]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: zww
     *@date: 2020/11/23
     */
    @RequestMapping(value = "/applyDeliverGoods", method = RequestMethod.POST, name = "申请发货")
    public ResponseTemplate applyDeliverGoods(HttpServletRequest request,String workOrderNumber){
        String userId = request.getHeader("userId");
        return storageService.applyDeliverGoods(workOrderNumber,userId);

    }

}
